# Importing Data
SOUTH_AFRICA<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Steel/TSA.xlsx",sheet = "Sheet1", range = "AE1:AE239")

# Checking the Imported Data
View(SOUTH_AFRICA)
# Creating Time Series Data
South_Africa_ts <- ts(SOUTH_AFRICA, start=c(2000,1), end=c(2019,09), frequency=12)
# Viewing and Checking the Created Time Series Data
South_Africa_ts
sum(is.na(South_Africa_ts))
library(forecast)
South_Africa_ts <- tsclean(South_Africa_ts)
South_Africa_ts

# Identification: Plotting the Time Series Data
plot(South_Africa_ts)

# Estimating the appropriate model
South_Africa_ts_model <- auto.arima(South_Africa_ts)
South_Africa_ts_model

# Forecasting
options(max.print=1000000)
South_Africa_ts_forecast <- forecast (South_Africa_ts_model, level=c(95), h=255)
plot(South_Africa_ts_forecast)
South_Africa_ts_forecast             

# Exporting
write.table(South_Africa_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Steel/SOUTH_AFRICA_TSA.csv", sep=",")
